var arr = [4,1,6,9,3,2,8,7];

function maopao() { 

  console.log(arr)
  for(let j =0;j<arr.length;j++){
    let left = 0;
    let right = 0;
    let mid = 0;
    let index = 0
  for(let i =0;i<arr.length-1-j;i++){
 
   
    if(arr[index] < arr[i]){
       index = i
    }
    
  }
  // console.log(index)
  left = arr[index];
  right = arr[arr.length-1-j]
  if(left > right){
    left = arr[index];
    mid = arr[arr.length-1-j]
    arr[arr.length-1-j] = left
    arr[index] = mid
  }
  console.log(arr)
}
  

 }
 maopao()